package com.cy.pj.sys.service.impl;

import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.common.exception.ServiceException;
import com.cy.pj.common.pojo.PageObject;
import com.cy.pj.common.utils.AssertUtils;
import com.cy.pj.sys.dao.SysSaleDao;
import com.cy.pj.sys.dao.SysUserDao;
import com.cy.pj.sys.dao.SysUserRoleDao;
import com.cy.pj.sys.pojo.SysSale;
import com.cy.pj.sys.pojo.SysSaleReason;
import com.cy.pj.sys.pojo.SysUser;
import com.cy.pj.sys.pojo.SysUserDept;
import com.cy.pj.sys.service.SysSaleService;
import com.cy.pj.sys.service.SysUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Slf4j
@Service
public class SysSaleServiceImpl implements SysSaleService {

    @Autowired
    private SysSaleDao sysSaleDao;


    @RequiredLog
    @Override
    public PageObject<SysSaleReason> findPageObjects(String name, Long pageCurrent) {

        AssertUtils.isValid(pageCurrent==null || pageCurrent<1,"当前页码值无效");

        int pageSize=3;
        //设置查询位置以及页面大小
        Page<SysUser> page= PageHelper.startPage(pageCurrent.intValue(),pageSize);
        //查询当前页数据
        List<SysSaleReason> records=
                sysSaleDao.findPageObjects(name);

        return new PageObject<>(page.getTotal(), records, pageSize, pageCurrent);
}

    @Override
    public int validById(Integer id, Integer valid) {
        AssertUtils.isValid(id==null||id<1, "参数值无效");
        AssertUtils.isValid(valid!=1&&valid!=0, "参数不合法。valid="+valid);
        //执行禁用或启用操作（admin为后续登陆用户
        int rows=sysSaleDao.validById(id, valid);

        AssertUtils.isServiceValid(rows==0,"此记录可能已经不存在");
        return rows;
    }
    @RequiredLog
    @Override
    public int saveObject(SysSale sysSale) {

        AssertUtils.isValid(sysSale==null, "保存对象不能为空");
        AssertUtils.isValid(StringUtils.isEmpty(sysSale.getName()),"收货人不能为空");

        int rows=sysSaleDao.insertObject(sysSale);

        return rows;
    }

}
